package util.ir;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;


import org.apache.lucene.queryParser.ParseException;

import org.apache.lucene.store.LockObtainFailedException;

import util.io.DirectoryInput;
import util.io.ZipInput;
import util.parser.DBPedia;
import util.parser.wikiXML.AnchorExtractor;
import util.wikiXML.objectModel.WikiLink;
import util.wikiXML.objectModel.WikiPage;

public class MetaDataExtractor implements Constants {

	private String index;

	
	String SEP ="\t";
	String DEL ="\"";
		
	
	/**
	 * @param args
	 */
	public void indexDirectory_hashing2(String path)
			throws LockObtainFailedException, IOException, ParseException {

		LinkedList<String> files = DirectoryInput.listDirectory(path, ".zip");

		HashSet<String> current = new HashSet<String>();

		// for each zip file
		for (int i = 0; i < files.size(); i++) {

			String temp = "file:" + files.get(i);

			String suffix = files.get(i);

			suffix = suffix.substring(suffix.lastIndexOf("/"), suffix.length());

			String zipPath = files.get(i);

			ZipInput zipFiles = new ZipInput(zipPath);
			LinkedList<InputStream> streams = zipFiles.getZipFilesInputStream();

			// For all the files in the zip file

			//System.out.println("Indexing zip file:" + zipPath);

			// Hash for zip file
		
			for (int j = 0; j < streams.size(); j++) {

				WikiPage wiki = AnchorExtractor.parseWikiFile(streams.get(j));

				System.out.println(DEL+wiki.getId() + DEL + SEP + DEL + wiki.getName() + DEL+ SEP + DEL+wiki.getCategories()+ DEL
						+ SEP +DEL + wiki.getTemplates() + DEL + SEP  + DEL+ wiki.getOutgoingWikis() +DEL + SEP+ DEL + wiki.getOutgoingAnchorText() + DEL);

			}

			
			zipFiles.close();

			// we create separate indexes for each zip file

		}

	}

	
	
	
	public static void main(String[] args) throws LockObtainFailedException, IOException, ParseException {
		// TODO Auto-generated method stub
		String path = "/media/sata/data/wikipedia/en/wikixml-20080724/";
		path = "/media/sata_/data/wikipedia/nl/wikixml/";
		MetaDataExtractor indexer = new MetaDataExtractor();

		indexer.indexDirectory_hashing2(path);
	}

}
